package com.oazon.moco.lan.core.http;


import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;

import java.nio.charset.Charset;

import android.util.Log;

import com.alibaba.fastjson.JSON;

public abstract class AbsHttpJsonEncoder<T> extends MessageToMessageEncoder<T>{

	private final static String CHARSET_NAME = "UTF-8";
	private static Charset UTF_8 = Charset.forName(CHARSET_NAME);

	protected ByteBuf encode(ChannelHandlerContext ctx, Object body) throws Exception {
		
		String jsonStr = JSON.toJSONString(body);
		ByteBuf encodeBuf = Unpooled.copiedBuffer(jsonStr,UTF_8);
		Log.d("Encode", jsonStr);
		return encodeBuf;
	}
}
